package biz.datalk.industrialland.admin.config;

import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.ErrorPageRegistrar;
import org.springframework.boot.web.server.ErrorPageRegistry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;

/**
 * 错误页面处理
 *
 * @author tarofang@163.com
 * @date 2020-01-09
 *
 */
@Configuration
public class ErrorPageConfig {

    @Bean
    public ErrorPageRegistrar errorPageRegistrar(){
        return new DatalkErrorPageRegistrar();
    }

    private static class DatalkErrorPageRegistrar implements ErrorPageRegistrar {
        @Override
        public void registerErrorPages(ErrorPageRegistry registry) {
            registry.addErrorPages(new ErrorPage(HttpStatus.FORBIDDEN, "/403"));
            registry.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/404"));

            registry.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/500"));
            registry.addErrorPages(new ErrorPage(HttpStatus.METHOD_NOT_ALLOWED, "/500"));
            registry.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500"));
        }

    }
}
